using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Collections;
using Microsoft.VisualBasic.FileIO;

namespace Windows_Explorer.Class
{
    class clsHistory
    {
        ArrayList history;
        int currentIndex;
        int size;
        public clsHistory()
        {
            history = new ArrayList();
            history.Add(SpecialDirectories.Desktop + "\\");
            currentIndex = 0;
            size = 50;
        }
        public void Add(string path)
        {
            if (path.Equals(history[history.Count - 1].ToString()))
            {
               return;
            }
            history.Add(path);
            if (history.Count > size)
                history.RemoveAt(0);
            currentIndex = history.Count-1;
        }      
        public string Back()
        {
            if (currentIndex > 0)
            {
                currentIndex--;
                return history[currentIndex].ToString();
            }
            return null;
        }
        public string BackItem(string item)
        {
            string path = "";
            string[] items = new string[100];
            if (history.Count == 0) return null;
            for (int i = 0; i < history.Count; i++)
            {
                string[] arr = history[i].ToString().Split('\\');
                items[i] = arr[arr.Length - 1];
            }
           for (int i = 0; i < items.Length; i++)
           {
               if (item == items[i]) path = history[i].ToString();
           }
            return path;
        }
        
        public string Forward()
        {
            if (currentIndex < history.Count-1)
            {
                currentIndex++;
                return history[currentIndex].ToString();
            }
            return null;
        }
        public string ForwardItem(string item)
        {
            string path = "";
            if (currentIndex <history.Count-1)
            {
                string[] items = new string[100];
                for (int i = 0; i < history.Count; i++)
                {
                    string[] arr = history[i].ToString().Split('\\');
                    items[i] = arr[arr.Length - 1];
                }
                for (int i = 0; i < items.Length; i++)
                {
                    if (item == items[i]) path = history[i].ToString();
                }
            }
            return path;
        }
        //Update toolstrip_Back_Dropdobuton
        public void InSertBack_DropDownbutton(TreeNode Node)
        {
            ToolStripMenuItem Items = new ToolStripMenuItem();
            Items.Text = Node.Text;
            Items.Tag = Node.Tag;
            Program.fmain.sbtnBack.DropDownItems.Add(Items);
            
        }
        //Update cho toolstripForward_dropdownbutton
        public void InsertForward_DropdownButton(TreeNode Node)
        {
            ToolStripMenuItem items = new ToolStripMenuItem();
            items.Text = Node.Text;
            items.Tag = Node.Tag;
            Program.fmain.sbtnForward.DropDownItems.Add(items);
        }
        /*
        public static ArrayList back, forward;
        //Ham cai dat trang thai cho nut Back va Forward
        public void SetbtnBackForward()
        {
            if (back.Count > 0)
            {
                Program.fmain.sbtnBack.Enabled = true;
            }
            if (forward.Count > 0)
            {
                Program.fmain.sbtnForward.Enabled = true;
            }
        }
        public void InsertItemToBack(TreeNode tn)
        {
            ToolStripMenuItem items = new ToolStripMenuItem();
            items.Text = tn.Name;
            items.Tag = tn;
            Program.fmain.sbtnBack.DropDownItems.Add(items);
        }
        public void InsertItemToForward(TreeNode tn)
        {
            ToolStripMenuItem items = new ToolStripMenuItem();
            items.Tag = tn;
            items.Text = tn.Text;
            Program.fmain.sbtnForward.DropDownItems.Add(items);
        }
        */
    }
}
